package com.wayne.cas.config;

import com.wayne.cas.login.UsernamePasswordKaptchaWebflowConfigurer;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.web.flow.CasWebflowConfigurer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
import org.springframework.webflow.engine.builder.support.FlowBuilderServices;

import javax.annotation.Resource;

@Configuration
public class CustomAuthenticationConfig {

    @Resource
    private FlowBuilderServices flowBuilderServices;

    @Resource
    private FlowDefinitionRegistry loginFlowRegistry;

    @Resource
    private ApplicationContext applicationContext;

    @Resource
    private CasConfigurationProperties casProperties;

    @Bean
    @Order(1)
    public CasWebflowConfigurer defaultWebflowConfigurer() {
        return new UsernamePasswordKaptchaWebflowConfigurer(
                flowBuilderServices,
                loginFlowRegistry,
                applicationContext,
                casProperties
        );
    }
}